package com.zxc.controller.marketing;

import com.zxc.entity.SalChance;
import com.zxc.entity.SalPlan;
import com.zxc.service.SalChanceService;
import com.zxc.service.SalPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private SalPlanService salPlanService;

    @Autowired
    private SalChanceService salChanceService;

    @RequestMapping("/{skipCount}/{pageSize}/{chcId}")
    @ResponseBody
    public Map<String,Object> getSalChanceListOrByCustName(@PathVariable Integer skipCount,
                                                           @PathVariable Integer pageSize,
                                                           @PathVariable(value = "chcId")Integer chcId){
        Map<String,Object> modelMap = new HashMap<>();
        //计算出略过的记录数
        int skipCounts = (skipCount-1)*pageSize;
        List<SalPlan> salPlanList = salPlanService.getSalPlanListByCondition(skipCounts,pageSize,chcId);
        modelMap.put("dataList",salPlanList);
        int total = salPlanService.selectCountSalPlanForMarketing(chcId);
        modelMap.put("total",total);
        SalChance salChance = salChanceService.selectSalChanceBychcId(chcId);
        if (salChance.getChcStatus().equals("3")){
            salChance.setChcStatus("开发成功");
        }else {
            salChance.setChcStatus("开发失败");
        }
        modelMap.put("salChance",salChance);
        return modelMap;
    }
}
